package com.generator.storageManage.inboundManage.service.impl;

import com.generator.storageManage.inboundManage.dao.InboundManageMap;
import com.generator.storageManage.inboundManage.pojo.*;
import com.generator.storageManage.inboundManage.service.IIinboundManageService;
import com.generator.util.PageModel;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

@Service
public class InboundManageService implements IIinboundManageService {

    @Autowired
    private InboundManageMap inboundManageMap;

    public InboundManageMap getInboundManageMap() {
        return inboundManageMap;
    }

    public void setInboundManageMap(InboundManageMap inboundManageMap) {
        this.inboundManageMap = inboundManageMap;
    }

    @Override
    //获取所有采购单的入库信息
    public PageModel<InboundInfo> queryInboundInfo(InboundInfoCondition condition,PageModel<InboundInfo> pageModel) {
        pageModel.setPageNum(pageModel.getPageNum()<=0?1:pageModel.getPageNum());
        pageModel.setPageSize(pageModel.getPageSize()<=0?1:pageModel.getPageSize());

        Page<Object> pageinfo = PageHelper.startPage(pageModel.getPageNum(), pageModel.getPageSize());

        List<InboundInfo> list = inboundManageMap.queryInboundInfo(condition);

        PageInfo<InboundInfo> warehousePageInfo = new PageInfo<InboundInfo>(list);

        pageModel.setData(new ArrayList<InboundInfo>(list));
        pageModel.setTotalPage(warehousePageInfo.getPages());
        pageModel.setTotalRows(warehousePageInfo.getTotal());

        return pageModel;
    }

    @Override
    //修改入库状态
    public void updateCgStatus(InboundInfoCondition condition) {
      inboundManageMap.updateCgStatus(condition);
    }

    @Override
    //通过采购单号获取采购单的信息
    public Purchase queryPurchaseById(Purchase purchase) {
        Purchase pc = inboundManageMap.queryPurchaseById(purchase);
        String checkstatus = pc.getCheckstatus();
        String str2 = "";
        if (checkstatus.equals("1")){
            str2 += "未审核";
        }
        else if(checkstatus.equals("2")){
            str2 += "审核中";
        }
        else if(checkstatus.equals("3")){
            str2 += "审核通过";
        }
        else if(checkstatus.equals("4")){
            str2 += "审核未通过";
        }
        pc.setCheckstatus(str2);
        return pc;
    }

    @Override
    //查询所有仓库名
    public List<WareHouse> queryAllWareHouse(){
        return inboundManageMap.queryAllWareHouse();
    }

    @Override
    //添加入库记录
    public Integer inbound(Inbound inbound) {

        return inboundManageMap.inbound(inbound);
    }
}
